package edu.neusoft.yuejian_09.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.adapter.TrainListAdapter;
import edu.neusoft.yuejian_09.bean.Train;
import edu.neusoft.yuejian_09.model.TrainModel;

public class TrainRumenActivity extends Activity implements RetrofitListener<List<Train>> {

    private RecyclerView recyclerView;
    private ImageView img_return,img_search;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_rumen);
        initViews();
        initEvents();
        getRumenlist();
    }

    private void initViews(){

        recyclerView= (RecyclerView)findViewById(R.id.rv_list3);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        img_return= (ImageView) findViewById(R.id.img_return);
        img_search=(ImageView) findViewById(R.id.search);

    }

    private void initEvents(){

        img_return.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        img_search.setOnClickListener(new View.OnClickListener(){//购买跳转
            @Override
            public void onClick(View v){
                Intent intent = new Intent(TrainRumenActivity.this, TrainSearchActivity.class);
                startActivity(intent);
            }
        });
    }

    void getRumenlist(){

        TrainModel trainModel=new TrainModel();
        trainModel.rumenlist(this);
    }

    @Override
    public void onSuccess(List<Train> data,int flag ){

        //System.out.printf("data");
        recyclerView.setAdapter(new TrainListAdapter(TrainRumenActivity.this,data));
    }

    @Override
    public void onFail(){ Toast.makeText(this, "网络发生错误", Toast.LENGTH_SHORT).show();}
}
